<template>
	<view class="new_fllow">
		<view class="fllow_form">
			<view><text>*</text>客户名称</view>
			<view class="form_right">
				<view :class="info && info.customer.name ? 'valueActive' : '' ">{{info && info.customer.name}}</view>
				<view class="iconfont icon-arrows_right"></view>
			</view>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款编号</view>
			<view class="form_input" >
				<input :class="number ? 'valueActive' : '' " type="text" v-model="number"  placeholder-style="font-size:30rpx;color: #999;" placeholder="请输入回款编号" class="">
			</view>
		</view>
		
		<view class="fllow_form">
			<view><text>*</text>合同编号</view>
			<view class="form_right">
				<view :class="info && info.num ? 'valueActive' : '' ">{{info && info.num}}</view>
				<view class="iconfont icon-arrows_right"></view>
			</view>
		</view>
		<view class="fllow_form">
			<view style="padding-left: 30rpx;">回款期数</view>
			<picker :range="numList" :value="index" @change="changeNum" :range-key="'num'">
				<view class="form_right">
					<view :class="plannum ? 'valueActive' : '' ">{{plannum ? plannum : '点击选择'}}</view>
					<view class="iconfont icon-arrows_right"></view>
				</view>
			</picker>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款日期</view>
			<picker mode="date" @change="changeTime">
				<view class="form_right">
					<view :class="return_time ? 'valueActive' : '' ">{{return_time ? return_time : '点击选择'}}</view>
					<view class="iconfont icon-arrows_right"></view>
				</view>
			</picker>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款金额</view>
			<view class="form_input" >
				<input type="text" :class="money ? 'valueActive' : '' " v-model="money"  placeholder-style="font-size:30rpx;color: #999;" placeholder="请输入回款金额" class="">
			</view>
		</view>
		<view class="fllow_form">
			<view><text>*</text>回款方式</view>
			<picker :value="index" @change="changeType" :range="type">
				<view class="form_right">
					<view :class="return_type ? 'valueActive' : '' ">{{return_type ? return_type : '点击选择'}}</view>
					<view class="iconfont icon-arrows_right"></view>
				</view>
			</picker>
		</view>
		
		<!-- 附加信息 -->
		<view class="info_head">附加信息</view>
		
		<!-- 审核信息 -->
		<examine-template :remindPeople="remindPeople" @delExamine="delRemind"></examine-template>
		<view id="btn" class="btn_g bg-blue button-hover round" @click="$noMultipleClicks(saveFollow)">
			保存
		</view>
	</view>
</template>

<script>
	import { BASE_IMG_URL } from '@/util/api.js'
	import { netSelect, netContractDetail, netPaymentNum, netAddPayment } from '@/api/kehu.js'
	import { netSetForm, netStaffDefaultReviewer } from '@/api/index.js'
	import formItem from '@/components/form/formitem.vue'
	import { commonF } from '@/common/common'
	export default {
		mixins:[commonF],
		components:{
			formItem
		},
		data() {
			return {
				noClick:true,    //防止  重复点击
				type:[],   //回款方式 
				index:null,
				numList:[],   //回款  期数
				info:null,   //合同信息
				id:'',
				plannum:'',
				plan_id:'',   //回款  期数id
				number:'',   //回款  编号 
				money:'',   //回款  金额
				return_time:'',   //  回款  日期
				return_type:'',   //回款  方式
				remarks:'',   //备注
				flow_staff_id:'',   //流程 审批人id
				BASE_IMG_URL:BASE_IMG_URL,
				remindPeople:[], //提醒谁看
				remindType:'contract',
				otherForm:[]
			}
		},
		onLoad(options) {
			this.id = options.id
			//获取 form
			this.otherForm = []
			this.getForm()
			
			//获取 合同 信息
			this.getInfo()
			//获取 回款方式 
			this.getType()
			//获取 回款  期数
			this.getNum()
		},
		onShow() {
			this.getDefaultRemind()
		},
		//监听  页面 卸载
		onUnload() {
			uni.removeStorageSync('remindlist')
		},
		methods: {	
			getForm() {
				netSetForm({type:'examine'}).then(res=>{
					res = res.data.data
					res.forEach(ele=>{
						if(ele.id.indexOf('other') != -1) {
							this.otherForm.push(ele)
						}
					})
				})
			},
			changeOtherData(name,value,obj) {
				let arr = this.otherForm
				arr.forEach((ele,index) => {
					if(ele.id == obj.id){
						ele.value = value
						this.$set(this.otherForm,index,ele)
					}
				})
			},
			getType() {
				netSelect().then(res=>{
					this.type = res.data['回款方式']
				})
			},
			//获取合同 详情信息
			getInfo() {
				netContractDetail({id:this.id}).then(res=>{
					this.info = res.data
				})
			},
			//获取  回款  期数
			getNum() {
				netPaymentNum({contract_id:this.id}).then(res=>{
					this.numList = res.data
					console.log(this.numList,'回款期数')
				})
			},
			//改变  回款  期数
			changeNum(e) {
				this.plan_id = this.numList[e.detail.value].id
				this.plannum = this.numList[e.detail.value].num
				// console.log(this.numList)
				// console.log(e.detail.value)
			},
			//改变 回款  方式
			changeType(e) {
				this.return_type = this.type[e.detail.value]
			},
			//计划 回款  日期
			changeTime(e) {
				this.return_time = e.detail.value
			},
			
			saveFollow() {
				let {
					number,   //回款  编号 
					money,   // 回款  金额
					return_time,   //  回款  日期
					return_type,   // 回款  方式
					remarks,   //备注
					info,
					plan_id,   //回款  期数id
					remindPeople
				} = this
				if(!number) {
					uni.showToast({
						title:'请输入回款编号',
						icon:'none'
					})
					return
				}
				if(!money) {
					uni.showToast({
						title:'请输入回款金额',
						icon:'none'
					})
					return
				}
				if(!return_time) {
					uni.showToast({
						title:'请选择回款日期',
						icon:'none'
					})
					return
				}
				if(!return_type) {
					uni.showToast({
						title:'请选择回款方式',
						icon:'none'
					})
					return
				}
				if(!remindPeople || remindPeople.length == 0) {
					uni.showToast({
						title:'请选择回款审批人',
						icon:'none'
					})
					return
				}
				let arr = []
				remindPeople.forEach(ele=>{
					arr.push(ele.id)
				})
				let flow_staff_id = arr.join(',')
				let params = {
					customer_id: info.customer.id,
					contract_id: info.id,
					number,  //回款  编号 
					money,   // 回款  金额
					return_time,   // 回款  日期
					return_type,   // 回款  方式
					plan_id,   //回款  期数id
					remarks,
					flow_staff_ids:flow_staff_id
				}
				let arrlist = []
				this.otherForm.forEach(ele=>{
					arrlist.push({
						name:ele.id,
						required: ele.config.required,
						msg: ele.config.placeholder,
						value:ele.value
					})
				})
				for(let i = 0; i < arrlist.length ; i++) {
					if(arrlist[i].required && !arrlist[i].value){
						uni.showToast({
							title: arrlist[i].msg,
							icon:'none'
						})
						return
					}
					params[arrlist[i].name] = arrlist[i].value
				}
				netAddPayment(params).then(res=>{
					uni.showToast({
						title: res.msg,
						icon:'none'
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},2000)
				})
			}
		}
	}
</script>

<style lang="scss">
	.info_head{
		height: 80rpx;
		line-height: 80rpx;
		font-size: 30rpx;
		color: #999;
		padding-left: 69rpx;
	}
.valueActive{
	color:#333;
}
.new_fllow {
	margin-top: 40rpx;
	font-size: 28rpx;
	.fllow_form {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #EAEAEA;
		// padding: 0 24rpx;
		font-size: 32rpx;
		color: #999;
		.form_right {
			display: flex;
			color: #666;
			font-size: 32rpx;
			margin-right: 30rpx;
			image {
				width: 40rpx;
				height: 40rpx;
				margin: 28rpx 5rpx 0 0;
			}
		}
		text {
			color: #f00;
			// margin-left: 10rpx;
			padding-left: 30rpx;
		}
		.form_input {
			margin-right: 30rpx;
			input {
				// height: 100rpx;
				// line-height: 100rpx;
				text-align: right;
				// margin-right: 10rpx;
				color: #333;
			}
		}
		.fllow_button {
			margin-top: 15rpx;
		}
	}
	.fllow_file_li{
		padding:24rpx 34rpx;
		background:#fff;
		border-bottom:1rpx solid #EAEAEA;
		.fil_li{
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom:14rpx;
			.fileimg{
				width:20rpx;
				height:20rpx;
			}
			.filename{
				font-size:24rpx;
				color:#999999;
			}
			.closeimg{
				width:32rpx;
				height:32rpx;
			}
		}
	}
	.imglist{
		padding:24rpx 34rpx;
		background:#fff;
		border-bottom:1rpx solid #EAEAEA;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
		.imgbox{
			width:160rpx;
			height:160rpx;
			margin-right:14rpx;
			position: relative;
			margin-bottom:24rpx;
			border:1rpx solid #EAEAEA;
			.delimg{
				width:32rpx;
				height:32rpx;
				border-radius:50%;
				position: absolute;
				right:-16rpx;
				top:-16rpx;
				background:rgba(0,0,0,0.5);
				z-index: 2;
			}
			.selfimg{
				width:160rpx;
				height:160rpx;
			}
		}
	}
	.fllow_area {
		background-color: #fff;
		padding: 0 30rpx;
		margin-bottom: 30rpx;
		.area_head {
			height: 100rpx;
			line-height: 100rpx;
			text {
				color: #f00;
			}
		}
		textarea {
			width: 100%;
			height: 300rpx;
			background: #f8f8f8;
		}
	}
	.follow_task {
		height: 80rpx;
		line-height: 80rpx;
	}
	#btn{
		width: 500rpx;
		height: 88rpx;
		background: #03AA96;
		border-radius: 29rpx;
		font-size: 34rpx;
		color: #fff;
		line-height: 88rpx;
	}
}
</style>
